<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@include file="_include.jsp" %>

<html>
<%--路径 /forum/signin--%>
<head>
    <script src="${pageContext.request.contextPath}/resources/js/jquery-2.1.1.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>signin</title>
</head>
<body>
<h1>signin</h1>

name:<input id="name" value=""><br/>
password:<input type="password" id="password" value=""><br/>
<button id="submit">提交</button>
<p id="showInfo"></p>

<script type="text/javascript">
    $(document).ready(function () {
        $('#name').val(localStorage.userName ? localStorage.userName : '');
        $('#password').val(localStorage.password ? localStorage.password : '');
    });


    $('#submit').click(function () {
        var name = $('#name').val();
        var password = $('#password').val();
        if (!(name && password)) {
            alert("用户名 密码 不能为空");
            return;
        }
        var upData = {
            "name": name,
            "password": password
        };
        localStorage.userName = name;
        localStorage.password = password;

        console.log(localStorage.userName);
        console.log(localStorage.password);

        $.ajax({
            type: 'POST',
            url: '/forum/signin',
            data: JSON.stringify(upData),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (typeof data === 'string') {
                    data = JSON.parse(data);
                }
                if (data.isSucc === "true") {
                    window.location = "home";
                } else {
                    $("#showInfo").text(data.errMsg);
                }
            }, error: function (errMsg) {
                console.log(errMsg);
                $("#showInfo").text(errMsg);
            }
        });
    });
</script>
</body>
</html>
